package com.wc.alorithm_blue_bridge._模拟.录入成绩;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/12/20 16:42
 * @description
 * https://www.lanqiao.cn/problems/20092/learning/?contest_id=228
 */
public class Main {
    /**
     * 思路：遍历找 G1
     * 枚举每一个 G, 把他当做 国特
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static char[] cs;

    public static void main(String[] args) {
        cs = sc.next().toCharArray();
        int n = cs.length, res = 0;
        // 暴力模拟每一个 G 当做单独的国特
        for (int i = 0; i < n; i++) {
            if (cs[i] == 'G') {
                int tmp = 0, flg1 = 0, flg2 = 0, flg3 = 0, flgG2 = 0, flgG3 = 0, flgGG = 0;
                for (int j = 0; j < n; j++) {
                    if (j == i) continue;
                    if (cs[j] == '1') flg1++;
                    else if (cs[j] == '2') flg2++;
                    else if (cs[j] == '3') flg3++;
                    else if (j + 1 < n && j + 1 != i){
                        if(cs[j + 1] == '1') {
                            tmp++;
                            j++;
                        } else if (cs[j + 1] == '2') {
                            flgG2++;
                            j++;
                        } else if (cs[j + 1] == '3') {
                            flgG3++;
                            j++;
                        } else if (cs[j + 1] == 'G') {
                            flgGG ++;
                            j++;
                        }
                    } else {
                        tmp = -1;
                        break;
                    }
                }
                if (flg1 == 0 || flg2 == 0 || flg3 == 0 || flgG2 == 0 || flgG3 == 0 || flgGG == 0) tmp = -1;
                res = Math.max(res, tmp);
            }
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

